local wangge = fk.CreateSkill{
    name = "XD__wangge",
    tags = {Skill.Compulsory},
    dynamic_desc = function (self, player, lang)
        if player:getMark("XD__wangge") > 1 then
            return "锁定技，出牌阶段开始时，你选择一名其他角色并弃置其一张牌，视为你对其使用一张【决斗】。"
        else
            return "锁定技，出牌阶段开始时，你选择一名其他角色并弃置其一张牌，视为其对你使用一张【决斗】；当你因此法累计造成2点伤害后，你须减1点体力上限，然后将“其对你”改为“你对其”。"
        end
    end,
}
Fk:loadTranslationTable{
    ["XD__wangge"] = "妄歌",
    [":XD__wangge"] = "锁定技，出牌阶段开始时，你选择一名其他角色并弃置其一张牌，视为其对你使用一张【决斗】；当你因此法累计造成2点伤害后，你须减1点体力上限，然后将“其对你”改为“你对其”。",
    ["#XD__wangge-choose1"] = "是否发动 妄歌，弃置一名其他角色一张牌，然后其视为对你使用一张【决斗】",
    ["#XD__wangge-choose2"] = "是否发动 妄歌，弃置一名其他角色一张牌，然后你视为对其使用一张【决斗】",
}

wangge:addEffect(fk.EventPhaseStart, {
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(wangge.name) and player.phase == Player.Play
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room:getOtherPlayers(player), function(p)
            return not p:isNude()
        end)
        local prompt = "#XD__wangge-choose1"
        local anim_type = "control"
        if player:getMark(wangge.name) > 1 then
            prompt = "#XD__wangge-choose2"
            anim_type = "offensive"
        end
        if #targets > 0 then
            local to = room:askToChoosePlayers(player, {
                min_num = 1,
                max_num = 1,
                targets = targets,
                skill_name = wangge.name,
                prompt = prompt,
                cancelable = true,
            })
            if #to > 0 then
                event:setCostData(self, {anim_type = anim_type, tos = to})
                return true
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = event:getCostData(self).tos[1]
        local ids = to:getCardIds("he")
        if #ids > 0 then
            local id = room:askToChooseCard(player, {
                target = to,
                flag = "he",
                skill_name = wangge.name,
            })
            ids = {id}
        end
        room:throwCard(ids, wangge.name, to, player)
        local card = Fk:cloneCard("duel")
        card.skillName = wangge.name
        if player:getMark(wangge.name) > 1 then
            if player:canUseTo(card, to) then
                room:useVirtualCard("duel",nil,player,{to},wangge.name)
            end
        else
            if to:canUseTo(card, player) then
                local use = room:useVirtualCard("duel",nil,to,{player},wangge.name)
                if use.damageDealt and use.damageDealt[to] then
                    room:addPlayerMark(player, wangge.name, use.damageDealt[to])
                    if player:getMark(wangge.name) > 1 then
                        room:changeMaxHp(player, -1)
                    end
                end
            end
        end
    end,
})

return wangge